package com.xxxx.controller;

import com.xxxx.pojo.HouseKeeper;
import com.xxxx.pojo.ResponseResult;
import com.xxxx.service.HKPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author Lionel
 * @Date 2021/3/11 16:57
 * Created by IntelliJ IDEA 2020.1.
 * Project: house
 * Description：搜索Controller
 */
@Controller
@RequestMapping("/result")
public class ResultController extends BaseController {

    @Autowired
    private HKPersonService hkPersonService;

    /**
     * 跳转搜索页面
     * @return
     */
    @GetMapping("/toSearchResult")
    public String toSearchResult(@RequestParam("typeId") Integer typeId, HttpSession session) {
        session.setAttribute("typeId",typeId);
        return "search-result";
    }

    /**
     * 跳转至家政人员页面
     * @return 商家资料页面
     */
    @GetMapping("/toHouseKeeper")
    public String toHouseKeeper(@RequestParam("id") Integer id, HttpSession session) {
        session.setAttribute("id",id);
        return "housekeeper";
    }

    @PostMapping("/loadSearchResult")
    @ResponseBody
    public ResponseResult<List<HouseKeeper>> loadSearchResult (
            @RequestParam("param") Integer param
    ) {
        ResponseResult<List<HouseKeeper>> result = new ResponseResult<>();
        List<HouseKeeper> list = hkPersonService.getHKListFuzzySelect(param);
        result.setData(list);
        return result;
    }
}
